<#include "../common/_layout.html" />
<@layout>

    <script language="javascript" type="text/javascript">
    $(document).ready(function(){
        document.onkeydown=nextpage
        document.onkeydown=nextpage
        var prevpage="problem/?p=${problemList.pageNumber-1}<#if problemList.pageSize!=50>&s=${problemList.pageSize}</#if>"
        var nextpage="problem/?p=${problemList.pageNumber+1}<#if problemList.pageSize!=50>&s=${problemList.pageSize}</#if>"
        function nextpage(event)
        {
            event=event?event:(window.event?window.event:null);
            <#if problemList.pageNumber&gt;1>if(event.keyCode==37)location=prevpage;</#if>
            <#if problemList.pageNumber<problemList.totalPage>if(event.keyCode==39)location=nextpage;</#if>
        }
        });
    </script>

    <div class="pagination pagination-centered">
        <div class="pull-left">
        <form class="form-search" action="problem/search">
            <div class="input-append">
            <input type="hidden" name="scope" value="title">
            <input type="text" class="input-medium search-query" name="word" placeholder="Try a random problem">
            <button type="submit" class="btn">Go</button>
            </div>
        </form>
        </div>
        <ul>
        <li class="<#if problemList.pageNumber==1>disabled</#if>"><a href="problem/?p=1<#if problemList.pageSize!=50>&s=${problemList.pageSize}</#if>">&lt;&lt;</a></li>
        <#if problemList.pageNumber&gt;1><li><a href="problem/?p=${problemList.pageNumber-1}<#if problemList.pageSize!=50>&s=${problemList.pageSize}</#if>">Prev</a></li></#if>
        <#if problemList??>
        <#assign start=problemList.pageNumber-4>
        <#assign end=problemList.pageNumber+4>
        <#if start<1><#assign end=end-start+1><#assign start=1></#if>
        <#if end&gt;problemList.totalPage ><#assign start=start-(end-problemList.totalPage)-1><#if start<1><#assign start=1></#if><#assign end=problemList.totalPage></#if>
        <#if end<start><#assign end=start></#if>
            <#list start..end as x>
            <li class="<#if x==problemList.pageNumber>active</#if>"><a href="problem/?p=${x}<#if problemList.pageSize!=50>&s=${problemList.pageSize}</#if>">${x}</a></li>
            </#list>
        </#if>
        <#if problemList.pageNumber<problemList.totalPage><li><a href="problem/?p=${problemList.pageNumber+1}<#if problemList.pageSize!=50>&s=${problemList.pageSize}</#if>">Next</a></li></#if>
        <li class="<#if problemList.pageNumber&gt;=problemList.totalPage>disabled</#if>"><a href="problem/?p=${problemList.totalPage}<#if problemList.pageSize!=50>&s=${problemList.pageSize}</#if>">&gt;&gt;</a></li>
        </ul>
        <div class="pull-right">
            <span class="badge badge-info">${problemList.pageNumber}/${problemList.totalPage} Pages</span>
            <span class="badge badge-info">${problemList.totalRow} Problems</span>
        </div>
    </div>
    
    <table id="problem-list" class="table table-hover table-condensed">
        <thead>
          <tr>
            <th></th>
            <th>ID</th>
            <th>Title</th>
            <th>AC</th>
            <th>Submit</th>
            <th>Ratio</th>
            <th>Date</th>
          </tr>
        </thead>
        <tbody>
        <#if problemList??>
        <#list problemList.list as Problem>
        <tr>
            <td><#if Problem.userResult??><image src="assets/images/<#if Problem.userResult==0>accepted.gif<#else>wrong.gif</#if>"/></#if></td>
            <td>${Problem.pid!}</td>
            <td><a href="problem/show/${Problem.pid!}"><#if Problem.status==false><del></#if>${Problem.title!}<#if Problem.status==false></del></#if></a></td>
            <td><a href="status/?pid=${Problem.pid!}&result=0">${Problem.accept!}</a></td>
            <td><a href="status/?pid=${Problem.pid!}">${Problem.submit!}</a></td>
            <td><#if Problem.submit&gt;0>${(Problem.accept/Problem.submit*100)?int}<#else>0</#if>%</td>
            <td>${Problem.ctime!}</td>
        </tr>
        </#list>
        </#if>
        </tbody>
    </table>

    <script type="text/javascript" src="assets/js/placeholder.js"></script>
    
    <link rel="stylesheet" href="assets/tablecloth/css/tablecloth.css">
    <script src="assets/tablecloth/js/jquery.metadata.js"></script>
    <script src="assets/tablecloth/js/jquery.tablesorter.min.js"></script>
    <script src="assets/tablecloth/js/jquery.tablecloth.js"></script>

    <script type="text/javascript" charset="utf-8">
      $(document).ready(function() {
                
        $("#problem-list").tablecloth({
          theme:"stats",
          condensed:true,
          sortable:true,
          striped:true,
          clean:true
        });
    });
    </script>

</@layout>